package com.wujunshen.algorithm.leetcode.basic;

/**
 * @author frank woo(吴峻申) <br>
 *     email:<a href="mailto:frank_wjs@hotmail.com">frank_wjs@hotmail.com</a> <br>
 * @date 2022/7/24 00:28<br>
 */
public class 字符串中的第一个唯一字符 {
  public int firstUniqChar(String s) {
    int length = s.length();
    if (length == 1) {
      return 0;
    }
    int[] cs = new int[26];
    for (char c : s.toCharArray()) {
      cs[c - 'a']++;
    }
    for (int i = 0; i < length; i++) {
      if (cs[s.charAt(i) - 'a'] == 1) {
        return i;
      }
    }
    return -1;
  }
}
